export function checkCount(content, max) {
  if (!content) {
    wx.showToast({
      title: '未输入数量',
      icon: "error",
    })
  } else {
    const count = parseInt(content);

    if (isNaN(count)) {
      wx.showToast({
        title: '请输入正确数量',
        icon: "error",
      })
    } else {
      if (max && count > maxEnable) {
        wx.showToast({
          title: '超出最大可用数量',
          icon: "error",
          onHide: () => {
            that.fetchEquipInfo();
          }
        })

      } else {
        return count;
      }
    }
  }
  return -1;
}

export function formVaildate(formData, rules) {
  // return new Promise()
  return new Promise((resolve, reject) => {
    Object.keys(rules).forEach(ruleKey => {
      if (!checkRequired(rules[ruleKey], formData[ruleKey])) {
        console.log("sa")

        return reject(rules[ruleKey].message)
      }
    })
    console.log("s")
    resolve(formData)
  })

}

function checkRequired(rule, data) {
  console.log(rule, !!data);
  if (rule.required) {
    return !!data
  } else {
    return true;
  }
}